package com.aegean.CommercialHotelBookSystem.admin.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.admin.business.IAdminBusiness;
import com.aegean.CommercialHotelBookSystem.factory.BusinessFactory;
import com.aegean.CommercialHotelBookSystem.factory.MyTools;
import com.aegean.CommercialHotelBookSystem.factory.MyTools.*;
import com.aegean.CommercialHotelBookSystem.model.Customer;
import com.aegean.CommercialHotelBookSystem.model.Service;
import com.aegean.CommercialHotelBookSystem.user.business.IUserBusiness;
import com.aegean.CommercialHotelBookSystem.user.dao.Impl.UserDaoImpl;

public class LoginAdmin extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String Admin_Login = MyTools.toChinese(request
				.getParameter("Admin_Login"));
		String Admin_Pwd = MyTools.toChinese(request.getParameter("Admin_Pwd"));
		if (Admin_Login == null || Admin_Pwd == null || Admin_Login.equals("")
				|| Admin_Pwd.equals("")) {
			request.getRequestDispatcher("Admin_login.jsp").forward(
					request, response);
		} else {
			IAdminBusiness business = BusinessFactory.createAdminBusiness();
			Service one = business.loginAdmin(Admin_Login, Admin_Pwd);
			if (one == null) {
				request.getRequestDispatcher("Admin_login.jsp").forward(
						request, response);
			} else {
				HttpSession session = request.getSession();
				session.setAttribute("Login_Admin", one);
				request.getRequestDispatcher("Admin_index.jsp").forward(
						request, response);
			}
		}
	}

}
